package 第一章基础算法.前缀和与差分.id795前缀和;

import java.util.Scanner;

/**
 * 前缀和模板
 * 用途：通过前缀和数组，快速获取元素数组中某一段区间的和
 */
public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        int[]nums = new int[n];
        for(int i = 0;i<n;i++){
            nums[i] = scanner.nextInt();
        }
        //前缀和数组
        int[]pre = new int[n+1];
        for(int i = 1;i<=n;i++){
            pre[i] = pre[i-1] + nums[i-1];
        }
        while (m-->0){
            int l = scanner.nextInt();
            int r = scanner.nextInt();
            int res = pre[r] - pre[l-1];
            System.out.println(res);
        }
    }
}
